package com.wlz.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@Controller
@RestController()
@RequestMapping("/order")
public class OrderController {

    @GetMapping("/getOrder")
    @ResponseBody
    @SentinelResource(value = "getOrder", blockHandlerClass = OrderController.class,blockHandler = "getOrderBlock")
    public String getOrderById(Integer id){
        return "success!";
    }

    public static String getOrderBlock(BlockException e){
        return "getOrder 已被sentinel流控";
    }

    @GetMapping("/testFuse")
    @SentinelResource(value = "order/testFuse", blockHandlerClass = OrderController.class,blockHandler = "getOrderBlock")
    public String testFuse() {
//        int i=1/0;
        return "Hello world  I am testFuse!  success! ";
    }

}
